package com.example.mybatisplus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.model.domain.HUser;
import com.example.mybatisplus.mapper.HUserMapper;
import com.example.mybatisplus.model.dto.PageDto;
import com.example.mybatisplus.service.HUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author yfy
 * @since 2021-12-30
 */
@Service
public class HUserServiceImpl extends ServiceImpl<HUserMapper, HUser> implements HUserService {
    @Autowired
    HUserMapper userMapper;

    @Override
    public Page<HUser> listByPage(PageDto page, HUser user) {
        Page<HUser> page1 = new Page<>(page.getPageNo(), page.getPageSize());
        QueryWrapper<HUser> wrapper = new QueryWrapper<>();
        if (user.getUsername() != null) {
            wrapper.lambda().like(HUser::getUsername, user.getUsername());
        }
        if (user.getUserType() != null) {
            wrapper.lambda().like(HUser::getUserType, user.getUserType());
        }
        if (user.getIdNum()!=null){
            wrapper.lambda().like(HUser::getIdNum,user.getIdNum());
        }
        if (user.getPhoneNum()!=null){
            wrapper.lambda().like(HUser::getPhoneNum,user.getPhoneNum());
        }
        page1 = userMapper.selectPage(page1, wrapper);
        return page1;
    }

    @Override
    public HUser login(HUser user) {
        QueryWrapper<HUser> wrapper =new QueryWrapper<>();
        wrapper.lambda().eq(HUser::getUsername,user.getUsername()).eq(HUser::getPassword,user.getPassword());
        System.out.println(user);
        HUser user1 =userMapper.selectOne(wrapper);
        System.out.println(user1);
        return user1;
    }
}
